﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OurFAS.Data
{
    public class AssetsHelper
    {
        public static List<Tbl_BaseAssets> GetBaseAssets()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> base_assets = entity.Tbl_BaseAssets.ToList();
            return base_assets;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssets()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> measure_assets = entity.Tbl_MeasureAssets.ToList();
            return measure_assets;
        }

        public static List<Tbl_SelfAssets> GetSelfAssets()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> self_assets = entity.Tbl_SelfAssets.ToList();
            return self_assets;
        }

        public static List<Dict_Dept> GetDepartments()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Dict_Dept> departments = entity.Dict_Dept.ToList();
            return departments;
        }

        public static List<Dict_Category> GetCategorys()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Dict_Category> categorys = entity.Dict_Category.ToList();
            return categorys;
        }

        public static List<Dict_GetType> GetGetTypes()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Dict_GetType> gettypes = entity.Dict_GetType.ToList();
            return gettypes;
        }

        public static List<Dict_MeasureInfo> GetMeasureInfos()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Dict_MeasureInfo> measureinfos = entity.Dict_MeasureInfo.ToList();
            return measureinfos;
        }

        public static List<Dict_UseFor> GetUseFors()
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Dict_UseFor> usefors = entity.Dict_UseFor.ToList();
            return usefors;
        }

        public static List<Tbl_BaseAssets> GetBaseAssetsByDepartment(string sDept)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.Where(c => c.Dept.Trim() == sDept).ToList();
            return result;
        }

        public static List<Tbl_SelfAssets> GetSelfAssetsByDepartment(string sDept)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.Where(c => c.Dept.Trim() == sDept).ToList();
            return result;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssetsByDepartment(string sDept)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.Where(c => c.Dept.Trim() == sDept).ToList();
            return result;
        }

        public static List<Tbl_BaseAssets> GetBaseAssetsByCategory(string sName)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.Where(c => c.AssetName.Trim() == sName).ToList();
            return result;
        }

        public static List<Tbl_SelfAssets> GetSelfAssetsByCategory(string sName)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.Where(c => c.AssetName.Trim() == sName).ToList();
            return result;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssetsByCategory(string sName)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.Where(c => c.AssetName.Trim() == sName).ToList();
            return result;
        }

        public static List<Tbl_BaseAssets> GetBaseAssetsByGetType(string sGetType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.Where(c => c.GetType.Trim() == sGetType).ToList();
            return result;
        }

        public static List<Tbl_SelfAssets> GetSelfAssetsByGetType(string sGetType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.Where(c => c.GetType.Trim() == sGetType).ToList();
            return result;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssetsByGetType(string sGetType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.Where(c => c.GetType.Trim() == sGetType).ToList();
            return result;
        }

        public static List<Tbl_BaseAssets> GetBaseAssetsByMeasureInfo(string sMeasureInfo)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            return result;
        }

        public static List<Tbl_SelfAssets> GetSelfAssetsByMeasureInfo(string sMeasureInfo)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            return result;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssetsByMeasureInfo(string sMeasureInfo)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            return result;
        }

        //根据设备编号进行查询
        public static Tbl_BaseAssets GetBaseAssetByCode(string sCode)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            Tbl_BaseAssets record = entity.Tbl_BaseAssets.Where(c => c.AssetCode.Trim() == sCode).FirstOrDefault();
            return record;
        }

        public static Tbl_SelfAssets GetSelfAssetByCode(string sCode)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            Tbl_SelfAssets record = entity.Tbl_SelfAssets.Where(c => c.AssetCode.Trim() == sCode).FirstOrDefault();
            return record;
        }

        public static Tbl_MeasureAssets GetMeasureAssetByCode(string sCode)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            Tbl_MeasureAssets record = entity.Tbl_MeasureAssets.Where(c => c.AssetCode.Trim() == sCode).FirstOrDefault();
            return record;
        }

        //查询
        public static List<Tbl_BaseAssets> GetBaseAssetsByKeyWords(string sKeyWords, string sAssetName,
            string sDepartment, string sGetType, string sMeasureInfo,
            string sUseFor, string sStartDate, int iDateType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.ToList();
            if (!string.IsNullOrEmpty(sKeyWords))
            {
                result = result.Where(c => c.AssetName.Contains(sKeyWords) || c.AssetCode.Contains(sKeyWords)
                    || c.AssetSpec.Contains(sKeyWords) || c.InBillCode.Contains(sKeyWords) || c.ProductionFirm.Contains(sKeyWords)
                    || c.InCharge.Contains(sKeyWords) || c.Dept.Contains(sKeyWords) || c.GBCode.Contains(sKeyWords)
                    || c.Location.Contains(sKeyWords) || c.TaskCode.Contains(sKeyWords) || c.AssetTagCode.Contains(sKeyWords)).ToList();
            }
            if (!string.IsNullOrEmpty(sAssetName))
            {
                result = result.Where(c => c.AssetName.Trim() == sAssetName).ToList();
            }
            if (!string.IsNullOrEmpty(sDepartment))
            {
                result = result.Where(c => c.Dept.Trim() == sDepartment).ToList();
            }
            if (!string.IsNullOrEmpty(sGetType))
            {
                result = result.Where(c => c.GetType.Trim() == sGetType).ToList();
            }
            if (!string.IsNullOrEmpty(sMeasureInfo))
            {
                result = result.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            }
            if (!string.IsNullOrEmpty(sUseFor))
            {
                result = result.Where(c => c.UseFor.Trim() == sUseFor).ToList();
            }
            if (!string.IsNullOrEmpty(sStartDate))
            {
                if (iDateType == 0)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) == Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 1)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) < Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 2)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) > Convert.ToInt32(sStartDate)).ToList();
                }
            }
            return result;
        }

        public static List<Tbl_SelfAssets> GetSelfAssetsByKeyWords(string sKeyWords, string sAssetName,
            string sDepartment, string sGetType, string sMeasureInfo,
            string sUseFor, string sStartDate, int iDateType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.ToList();
            if (!string.IsNullOrEmpty(sKeyWords))
            {
                result = result.Where(c => c.AssetName.Contains(sKeyWords) || c.AssetCode.Contains(sKeyWords)
                    || c.AssetSpec.Contains(sKeyWords) || c.InBillCode.Contains(sKeyWords) || c.ProductionFirm.Contains(sKeyWords)
                    || c.InCharge.Contains(sKeyWords) || c.Dept.Contains(sKeyWords) || c.GBCode.Contains(sKeyWords)
                    || c.Location.Contains(sKeyWords) || c.TaskCode.Contains(sKeyWords) || c.AssetTagCode.Contains(sKeyWords)).ToList();
            }
            if (!string.IsNullOrEmpty(sAssetName))
            {
                result = result.Where(c => c.AssetName.Trim() == sAssetName).ToList();
            }
            if (!string.IsNullOrEmpty(sDepartment))
            {
                result = result.Where(c => c.Dept.Trim() == sDepartment).ToList();
            }
            if (!string.IsNullOrEmpty(sGetType))
            {
                result = result.Where(c => c.GetType.Trim() == sGetType).ToList();
            }
            if (!string.IsNullOrEmpty(sMeasureInfo))
            {
                result = result.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            }
            if (!string.IsNullOrEmpty(sUseFor))
            {
                result = result.Where(c => c.UseFor.Trim() == sUseFor).ToList();
            }
            if (!string.IsNullOrEmpty(sStartDate))
            {
                if (iDateType == 0)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) == Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 1)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) < Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 2)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) > Convert.ToInt32(sStartDate)).ToList();
                }
            }
            return result;
        }

        public static List<Tbl_MeasureAssets> GetMeasureAssetsByKeyWords(string sKeyWords, string sAssetName,
            string sDepartment, string sGetType, string sMeasureInfo,
            string sUseFor, string sStartDate, int iDateType)
        {
            OurFasDBEntities entity = new OurFasDBEntities();
            List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.ToList();
            if (!string.IsNullOrEmpty(sKeyWords))
            {
                result = result.Where(c => c.AssetName.Contains(sKeyWords) || c.AssetCode.Contains(sKeyWords)
                    || c.AssetSpec.Contains(sKeyWords) || c.InBillCode.Contains(sKeyWords) || c.ProductionFirm.Contains(sKeyWords)
                    || c.InCharge.Contains(sKeyWords) || c.Dept.Contains(sKeyWords) || c.GBCode.Contains(sKeyWords)
                    || c.Location.Contains(sKeyWords) || c.TaskCode.Contains(sKeyWords) || c.AssetTagCode.Contains(sKeyWords)).ToList();
            }
            if (!string.IsNullOrEmpty(sAssetName))
            {
                result = result.Where(c => c.AssetName.Trim() == sAssetName).ToList();
            }
            if (!string.IsNullOrEmpty(sDepartment))
            {
                result = result.Where(c => c.Dept.Trim() == sDepartment).ToList();
            }
            if (!string.IsNullOrEmpty(sGetType))
            {
                result = result.Where(c => c.GetType.Trim() == sGetType).ToList();
            }
            if (!string.IsNullOrEmpty(sMeasureInfo))
            {
                result = result.Where(c => c.MeasureInfo.Trim() == sMeasureInfo).ToList();
            }
            if (!string.IsNullOrEmpty(sUseFor))
            {
                result = result.Where(c => c.UseFor.Trim() == sUseFor).ToList();
            }
            if (!string.IsNullOrEmpty(sStartDate))
            {
                if (iDateType == 0)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) == Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 1)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) < Convert.ToInt32(sStartDate)).ToList();
                }
                else if (iDateType == 2)
                {
                    result = result.Where(c => Convert.ToInt32(c.StartUseDate) > Convert.ToInt32(sStartDate)).ToList();
                }
            }
            return result;
        }

    }
}
